/**
 * Copyright (c)  HeiFeiDeFengZheng.Co.Ltd. All rights reserved.
 **/
package com.defu.newmall.common;

import lombok.Data;

import java.io.Serializable;

/**
 * 功能描述：
 *
 * @author huifeidefengzheng
 * @since 2024-01-15
 **/
@Data
public class Result<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    private int code;
    private String msg;
    private T data;
    private Long total;
    private Long pageSize;

    private Result result(int code, String msg, T data) {
        Result result = new Result();
        result.setCode(code);
        result.setData(data);
        result.setMsg(msg);
        return result;
    }

    private Result result(int code, String msg, T data, Long total, Long pageSize) {
        Result result = new Result();
        result.setCode(code);
        result.setData(data);
        result.setMsg(msg);
        result.setTotal(total);
        result.setPageSize(pageSize);
        return result;
    }

    public Result fail() {
        return result(500, "error", null);
    }

    public Result suc() {
        return result(200, "success", null);
    }

    public Result suc(T data) {
        return result(200, "success", data);
    }

    public Result suc(T data, Long total, Long pageSize) {
        return result(200, "success", data, total, pageSize);
    }

    public Result suc(T data, Long total) {
        return result(200, "success", data, total, null);
    }

    public Result fail(String msg) {
        return result(500, msg, null);
    }
}
